﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class UIItemView : MonoBehaviour
{
    private GameObject _cell;
    private GameObject _item;
    private Transform[] _itemCells;
    private int _itemCellsLength = 3;
    void Awake()
    {
        Init();
    }

    void Start()
    {
        SetItems(new Color[]
        {
            Color.black, Color.blue
        });
    }

    void Init()
    {
        _cell = (GameObject)Resources.Load("Cell");
        _item = (GameObject) Resources.Load("Item");
        _itemCells = new Transform[_itemCellsLength];
        for (int i = 0; i < _itemCellsLength; i++)
        {
            GameObject tempCell = (GameObject) Instantiate(_cell);
            tempCell.transform.SetParent(transform);
            tempCell.transform.localScale = Vector3.one;
            _itemCells[i] = tempCell.transform;
        }
    }

    void SetItems(Color[] itemColor)
    {
        for (int i = 0; i < itemColor.Length; i++)
        {
            GameObject tempItem = (GameObject) Instantiate(_item);
            tempItem.transform.SetParent(_itemCells[i]);
            tempItem.transform.localScale = Vector3.one;
            tempItem.transform.localPosition = Vector3.zero;
            tempItem.GetComponent<Image>().color = itemColor[i];
        }
    }
}
